﻿using Commonality.DAL.MySQL;
using Commonality.Model.Classify;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Commonality.Model;
using Commonality.DAL.WZS_SFCS;

namespace Merge.BLL.CaverForm
{
    public partial class CaverInfoForm : Form
    {
        public static CaverInfoForm caverInfoForm;
        public CaverInfoForm()
        {
            InitializeComponent();
            caverInfoForm = this;
        }

        private void CaverInfoForm_Load(object sender, EventArgs e)
        {

        }

        private void UsnTextBox_TextChanged(object sender, EventArgs e)
        {
            if (UsnTextBox.Text.Length != 17) return;
            string usn = UsnTextBox.Text + "\r\n";
            CaverInfoClass.LocatingCaver(usn);
            CaverInfoClass.GetInfoList(usn);
        }
    }
    public static class CaverInfoClass
    {
        public static string USN;

        public static void CaverInfoClassInit()
        {

        }

        public static void LocatingCaver(string usn)
        {
            CaverInfoForm.caverInfoForm.CaverNumberLabel.Text = "";
            string eig = "";
            CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "", KCAndBF.ZERO, Remark.ZERO);     //特征类
            MySqlFunction.TrayCellDataList.TrayCellDataList__Eigenvector_SELECT(usn, usn, ref eig);         //查询特征
            if (eig == "") { Log4Net.MsgInfo("查无此信息!");return; }
            CEigenvector.EigenvectorString2C(eig, ref cEigenvector);            //字符串转特征类
            try
            {
                int caverNumberA = 0;
                int caverNumberB = 0;
                caverNumberA = Caver.SearchClassReferenceA(ref cEigenvector)[0];
                caverNumberB = Caver.SearchClassReferenceB(ref cEigenvector)[0];
                Log4Net.MsgInfo(caverNumberA + "仓");
                Log4Net.MsgInfo(caverNumberB + "仓");
                if (caverNumberA>0 && caverNumberB>0)
                {
                    CaverInfoForm.caverInfoForm.CaverNumberLabel.Text =  "A" + caverNumberA%100 + "仓" + "B" + caverNumberB%200 + "仓";
                }
                else
                {
                    if (caverNumberA>0)
                    {
                        CaverInfoForm.caverInfoForm.CaverNumberLabel.Text = "A" + caverNumberA % 100 + "仓";
                    }
                    else
                    {
                        CaverInfoForm.caverInfoForm.CaverNumberLabel.Text = "B" + caverNumberB % 200 + "仓";
                    }
                }

            }
            catch (Exception)
            {
                Log4Net.MsgInfo("查无此同类仓");
            }

        }
        public static void GetInfoList(string usn)
        {
            CaverInfoForm.caverInfoForm.InfoDataListLabel.Text = "";
            string str = "";
            ProductCellData ProductCell1 = new ProductCellData() { usn = usn, usnInfo = new string[20], bin = new string[10] };
            str = SFCSDataDispose.GetKeyInfoFromView_DataDispose(usn, ref ProductCell1.usn, ref ProductCell1.usnInfo, ref ProductCell1.bin);
            foreach (var item in ProductCell1.usnInfo)
            {
                CaverInfoForm.caverInfoForm.InfoDataListLabel.Text += "\r\n" + item ;
            }
            
        }
    }
}
